/**
 * @param {number[][]} grid
 * @return {number}
 */

var maxAreaOfIsland = function (grid) {
    let row = grid.length
    let col = grid[0].length
    let max = 0
    for (let i = 0; i < row; i++) {
        for (let j = 0; j < col; j++) {
            // 找到陆地 就进行深度搜索
            if (grid[i][j] === 1) {
                max = Math.max(dfs(grid, i, j), max)
            }
        }
    }
    return max
    function dfs(grid, i, j) {
        if (i < 0 || i >= row || j < 0 || j >= col || grid[i][j] === 0) {
            return 0
        }
        // 找过之后就令当前的为海洋
        grid[i][j] = 0;
        // 计数
        let count = 1;
        // 接着找
        count += dfs(grid, i + 1, j);
        count += dfs(grid, i - 1, j);
        count += dfs(grid, i, j + 1);
        count += dfs(grid, i, j - 1);
        return count;
    }
};
console.log(maxAreaOfIsland([[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0]]))
